﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class PromotionPolicy : IAccessible<P_PromotionPolicy, PromotionPolicy>, ILogicEntity<P_PromotionPolicy, PromotionPolicy>
    {
        public int ID { get; set; }
        public DateTime BeginDate { get; set; }
        public DateTime EndDate { get; set; }
        public bool Enable { get; set; }
        public int ActiveCode { get; set; }
        public string AttachPolicy { get; set; }
        public DateTime CreateTime { get; set; }
        public string CreateUser { get; set; }
        public PromotionRange Range { get; set; }
        public string Summary { get; set; }

        protected override void Covariant(P_PromotionPolicy model)
        {
            if (model != null)
            {
                this.ActiveCode = model.ActiveCode;
                this.AttachPolicy = model.AttachPolicy;
                this.BeginDate = model.BeginDate;
                this.CreateTime = model.CreateTime;
                this.CreateUser = model.CreateUser;
                this.Enable = model.Enable;
                this.EndDate = model.EndDate;
                this.ID = model.ID;
                this.Range = (PromotionRange)model.Range;
                this.Summary = model.Summary;
            }
        }

        protected override P_PromotionPolicy Inverter(PromotionPolicy model)
        {
            if (model != null)
            {
                return new P_PromotionPolicy()
                {
                    ActiveCode = model.ActiveCode,
                    AttachPolicy = model.AttachPolicy,
                    BeginDate = model.BeginDate,
                    CreateTime = model.CreateTime,
                    CreateUser = model.CreateUser,
                    Enable = model.Enable,
                    EndDate = model.EndDate,
                    ID = model.ID,
                    Range = (int)model.Range,
                    Summary=model.Summary
                };
            }
            return null;
        }

        public PromotionPolicy Set(P_PromotionPolicy dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
